package com.situ.mall.controller.back;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mysql.fabric.xmlrpc.base.Data;
import com.situ.mall.common.ServerResponse;
import com.situ.mall.entity.Category;
import com.situ.mall.entity.Product;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.service.IProductService;

@Controller
@RequestMapping(value="/product")
public class ProductController {
	@Autowired
	private IProductService productService;
	
	//在网页点击到这
	@RequestMapping(value="/getProductPage")
	public String getProductPage() {
		return "/product/product_list";
	}
	
	@RequestMapping(value="/list")
	@ResponseBody
	public List<Product> list() {
		return productService.list();
	}
	
	@RequestMapping(value="/pageList")
	@ResponseBody
	public ServerResponse pageList(Integer page,Integer limit,Product product) {
		ServerResponse serverResponse = productService.pageList(page,limit,product);
		System.out.println(serverResponse);
		return serverResponse;
	}
	
	@RequestMapping(value="deleteById")
	@ResponseBody
	public ServerResponse deleteById(Integer id) {
		return productService.deleteById(id);
	}
	
	@RequestMapping(value="/deleteAll")
	@ResponseBody
	public ServerResponse deleteAll(String ids) {
		return productService.deleteAll(ids);
	}
	
	/*添加页面*/
	@RequestMapping(value="/getAddPage")
	public String getAddPage() {
		return "product/product_add";
	}
	
	@RequestMapping(value="/insert")
	@ResponseBody
	public ServerResponse insert(Product product) {
		System.out.println(product);
		return productService.insert(product);
	}
	
	/*修改页面*/
	@RequestMapping(value="/getUpdatePage")
	public String getUpdatePage(Integer id,Integer categoryId,Model model) {
		//展示本表格
		System.out.println(id);
		System.out.println(categoryId);
		Product product = productService.toUpDate(id);
		model.addAttribute("product",product);
		System.out.println(product);
		return "product/product_update";
	}
	/*修改*/
	@RequestMapping(value="/update")
	@ResponseBody
	public ServerResponse update(Product product) {
		System.out.println(product);
		return productService.update(product);
	}
}
